<!doctype html>
<html lang="en">

	<head>
		<meta charset="UTF-8" />
		<title>用户注册</title>
		<link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
		<link rel="stylesheet" type="text/css" href="css/style4.css" />
		<link rel="stylesheet" type="text/css" href="css/style2.css" />
		<link rel="stylesheet" type="text/css" href="css/reset.css" />
		<script type="text/javascript" src="js/jq.min.js"></script>
		<script type="text/javascript" src="js/bootstrap.js"></script>
		<script type="text/javascript" src="js/rem.js"></script>
	</head>

	<body>
		<div class="wrap">
			<!-- <header id="head">
				<h1>
				<img src="img/images/1_03.jpg"/>
				<span>返回</span>
			</h1>
				<h2>用户注册</h2>
				<h3>
				<img src="img/images/1_06.jpg"/>
			</h3>
			</header> -->
			<section>
				<h4><img src="img/images/1_11.jpg"/></h4>
				<form action="./password.php">
					<div class="form-group" id="fgroup">
						<div class="input-group">
							<div class="input-group-addon">
								<img src="img/images/1_18.jpg" />
							</div>
							<input type="text" id="inps" class="form-control" name="tel" placeholder="手机号">
						</div>
					</div>
					<div class="register">
						<input type="text" id="imgcode" placeholder="请输入验证码">
						<div style="width:50%"> 
							<img id="code" style="width: 100%;height: 100%;" src="../authcode.php" onclick="shuaxin()" />
						</div>
						<span id="code_erorr"></span>
					</div>
					<input type="hidden" name="openid" value="<?php echo $_GET['openid'] ?>">
					<div class="register">
						<input type="text" name="code" class="code" placeholder="短信验证码" />
						<button class="dot" disabled='disabled' type="button">获取验证码</button>
						<span id="code_erorrs"></span>
					</div>
					<span class="error"></span>
					<div class="btnes">
						<button disabled='disabled' class="btn btn-danger" id="register" style="margin-top: 0.16rem;">注册</button>
					</div>
				</form>
				<div class="info">
					<p><a href="https://pay.hispot.cn/gitscan/h5/login.php?openid=<?php echo $_GET['openid'] ?>">已有账号，去登录>></a></p>
				</div>
			</section>
		</div>
	</body>

</html>

<script>
	$(".dot").click(function() {
		var tel = $("#inps").val();
		if(tel == ''){
			alert('手机号不能为空');
			return false;
		}
		$.ajax({
			url:"../check_tel_register.php",
			data:"tel="+tel,
			success:function(msg) {
				if (msg == 1) {
					sendMessage(tel);
				}else{
					alert('该手机号已被注册');
				}
			}
		})
	})

	function sendMessage(tel) {
		$.ajax({
			url:"../sendMessages.php",
			data:"tel="+tel,
			success:function(msg) {
				if (msg == 1) {
					new invokeSettime(".dot");
				}else{
					alert('发送失败');
				}
			}
		})
	}

	$(".code").keyup(function() {
		var code = $(this).val();
		if (!code || code.length < 4) {
			return false;
		}
		var tel = $("#inps").val();
		$.ajax({
			url:"../check_code.php",
			data:"code="+code+"&tel="+tel,
			success:function(msg) {
				if (msg == 1) {
					$("#code_erorrs").html('短信验证成功');
					$("#register").removeAttr('disabled');
				}else{					
					$("#code_erorrs").html('短信验证失败');
				}
			}
		})
	})

	function shuaxin(){
	  document.getElementById('code').src = "../authcode.php?"+Math.random();
	} 

	$("#imgcode").keyup(function() {
		var imgcode = $(this).val();
		if (!imgcode || imgcode.length < 4) {
			return false;
		}
		$.ajax({
			url:"../check_php_code.php",
			data:"imgcode="+imgcode,
			success:function(msg) {
				if (msg == 1) {
					$("#code_erorr").html('验证码验证成功');
					$(".dot").removeAttr('disabled');
				}else{
					$("#code_erorr").html('验证码验证失败');

				}
			}
		})
	})

	function invokeSettime(obj){
    var countdown=60;
    settime(obj);
    function settime(obj) {
        if (countdown == 0) {
            $(obj).attr("disabled",false);
            $(obj).text("获取验证码");
            countdown = 60;
            return;
        } else {
            $(obj).attr("disabled",true);
            $(obj).text("(" + countdown + ") s 重新发送");
            countdown--;
        }
        setTimeout(function() {
                    settime(obj) }
                ,1000)
    }
}
</script>
